const lbbService = require('../../../pages/service/service.js');
const app = getApp();
const lbbTaskService = require('../service/task-service.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        patrolList: [],
        columns: [],
        handleReason: '',
        show: false,
        showSelect: false,
        equId: '',
        hospitalId: '',
        equType: '',
        onBeforeClose(action, done) {
            if (action == 'confirm') {
                return false
            } else {
                return true
            }
        },
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        if (options.timeType == 0) {
            wx.setNavigationBarTitle({
                title: '1分钟大保养'
            })
        } else if (options.timeType == 1) {
            wx.setNavigationBarTitle({
                title: '2-5分钟大保养'
            })
        }else if (options.timeType == 2) {
            wx.setNavigationBarTitle({
                title: '5分钟以上大保养'
            })
        }
        this.setData({
            hospitalId: options.hospitalId,
            timeType: options.timeType,
            scrollHeight: app.getScrollHeight(0),
        })
        this.getPatrolList()
    },
    //获取未巡检列表
    getPatrolList() {
        let that = this
        lbbTaskService.getStatisticsTimeEquList({
            hospitalId: that.data.hospitalId,
            timeType:that.data.timeType
        }, function (res) {
            // wx.hideLoading()
            that.setData({
                patrolList: res.data,
            })
        })
    },
    //处理/查看
    handleShow(e) {
        console.log(e)
        this.setData({
            show: true,
            equId: e.currentTarget.dataset.quid,
            handleStatus: e.currentTarget.dataset.handlestatus,
            handleReasonShow: e.currentTarget.dataset.handlereason,
            handleDate: e.currentTarget.dataset.handledate,
            handleReasonText: '',
            handleReason: '',
        })
    },
    btnSelect() {
        this.setData({
            showSelect: true
        })
    },
    okSelect(e) {
        console.log(e)
        this.setData({
            handleReasonText: e.detail.value.text,
            handleReason: e.detail.value.value,
            showSelect: false
        })
    },
    closeSelect() {
        this.setData({
            showSelect: false
        })
    },
    // 提交
    okSubmit() {
        let that = this
        if (!that.data.handleReasonText) {
            wx.showToast({
                title: '请选择原因',
                icon: 'error',
                duration: 2000
            })
            return
        } else {
            wx.showLoading({
                title: '加载中...',
                mask: true
            });
            lbbTaskService.handleEquInspect({
                equId: that.data.equId,
                hospitalId: that.data.hospitalId,
                equType: that.data.equType,
                handleReason: that.data.handleReasonText
            }, function (res) {
                console.log('444',res)
                wx.showLoading({
                    title: '加载中...',
                    mask: true
                });
             setTimeout(()=>{
                that.setData({
                    show: false
                })
                that.getPatrolList()
                },1000)
            })
        }
    },
    //关闭
    closebtn() {
        this.setData({
            show: false
        })
    },
    getDictByCode(code) {
        let that = this
        lbbTaskService.getDictByCode({
            code
        }, function (res) {
            res.data.forEach(item => {
                item.text = item.label
            })
            that.setData({
                columns: res.data
            })
        })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})